﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using External.Controls.Controls;
using External.Controls.Interfaces;
using External.Core;

namespace External.Controls.ModelViews
{
    /// <summary>
    /// Контроллер отображения места
    /// </summary>
    public class SeatViewModel : IDrawable
    {
        /// <summary>
        /// Оригинальная модель места
        /// </summary>
        public Seat Seat { get; set; }

        public SeatViewModel(Seat seat)
        {
            Seat = seat;
        }

        private SeatDesignerItem _item;

        public FrameworkElement Geometry
        {
            get
            {
                if (_item == null)
                {
                    _item = new SeatDesignerItem();
                    _item.Content = this;
                    HallCanvas.SetLeft(_item, Seat.Left);
                    HallCanvas.SetTop(_item, Seat.Top);
                }
                
                return _item;
            }
        }

        public int Number
        {
            get { return Seat.Number; }
            set { Seat.Number = value; }
        }
    }

    public class BoolToBrushConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if ((bool)value)
            {
                return Brushes.Gold;
            }
            else
            {
                if (parameter != null)
                    return parameter;
                return Brushes.White;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class BoolToThicknessConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if ((bool)value)
            {
                return new Thickness(3);
            }
            else
            {
                return new Thickness(1);
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class BoolToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if ((bool)value)
            {
                return Visibility.Visible;
            }
            else
            {
                return Visibility.Collapsed;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}